package com.fenghongzhang.day005;

import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;


/**
 * A simple {@link Fragment} subclass.
 */
public class SendFragment extends Fragment {
    private EditText fgEdit;
    private Button fgSend;
    public SendFragment() {
        // Required empty public constructor
    }


    //1接口
    public interface SendListener{
        void send(String s);
    }
    //2声明一个属性
    private SendListener sendListener;
    //3,sendListener?
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        //给接口赋值
        sendListener = (SendListener) getActivity();

        View inflate = inflater.inflate(R.layout.fragment_send, container, false);
        fgEdit = (EditText) inflate.findViewById(R.id.fg_edit);
        fgSend = (Button) inflate.findViewById(R.id.fg_send);

        fgSend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String string = fgEdit.getText().toString();
                //发送
                sendListener.send(string);
            }
        });

        return inflate;
    }
}
